<!-- 收藏列表 -->
<template>
	<view class="page_box">
		<!-- 总收藏数 -->
		<view class="head_box u-flex u-row-between" v-show="!isEmpty">
			<view class="count-box">
				共
				<text class="all-num">{{ total }}</text>
				篇文章
			</view>
		</view>

		<!-- 收藏列表 -->
		<view class="content_box">
			<scroll-view scroll-y="true" @scrolltolower="loadMore" class="scroll-box">
				<u-checkbox-group @change="checkboxGroupChange" activeColor="#e9b461">
					<view class="collect-list u-flex" v-for="(item, index) in myarticleList" :key="index">
						<u-checkbox v-show="isEdit" :name="item.id" shape="circle" v-model="item.checked"></u-checkbox>
						<shopro-star-card :image="item.image" :title="item.title"
							@click="$Router.push({ path: '/pages/news/news', query: { id: item.id } })">
						</shopro-star-card>
					</view>

				</u-checkbox-group>
				<!-- 缺省页 -->
				<shopro-empty v-show="isEmpty" :image="$IMG_URL + '/imgs/empty/empty_news.png'" tipText="暂无收藏"
					btnText="去首页逛逛" @click="$Router.pushTab('/pages/index/index')"></shopro-empty>
				<!-- 更多 -->
				<u-loadmore v-show="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc" />
			</scroll-view>
		</view>
		
		<!-- 登录提示 -->
		<shopro-auth-modal></shopro-auth-modal>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				isEmpty: false,
				isEdit: false,
				isAllSel: false, //是否全选
				selList: [],
				myarticleList: [],
				total: 0,
				loadStatus: 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
				currentPage: 1,
				lastPage: 1
			};
		},
		computed: {},
		onLoad() {
			this.getMyArticleList();
		},
		methods: {
			// 单选
			checkboxGroupChange(e) {
				this.selList = e;
				this.isAllSel = this.myarticleList.every(item => item.checked);
			},

			// 编辑
			onSet() {
				this.isEdit = !this.isEdit;
			},

			// 全选
			onAllSel(e) {
				this.isAllSel = e.value;
				this.selList = [];
				this.myarticleList.forEach(item => {
					e.value && this.selList.push(item.news_id);
					this.$set(item, 'checked', e.value);
				});
			},

			// 加载更多
			loadMore() {
				if (this.currentPage < this.lastPage) {
					this.currentPage += 1;
					this.getMyArticleList();
				}
			},
			/*
			getMyArticleList() {
							let that = this;
							that.loadStatus = 'loading';
							that.$api('cms.mypushList', {
								pre_page: 10,
								page: that.currentPage
							}).then(res => {
								if (res.code === 1) {
									that.total = res.data.total;
									that.myarticleList = [...that.myarticleList, ...res.data.data];
									that.lastPage = res.data.last_page;
									if (that.currentPage < res.data.last_page) {
										that.loadStatus = 'loadmore';
									} else {
										that.loadStatus = 'nomore';
									}
								}
							});
						},
			
			
			// 收藏列表
			getFavoriteList() {
				let that = this;
				let list = [];
				that.loadStatus = 'loading';
				that.$http('index.mypushList', {
					pre_page: 10,
					page: that.currentPage
				}).then(res => {
					if (res.code === 1) {
						that.total = res.data.total;
						list = res.data.data;
						list.map(item => {
							that.$set(item, 'checked', false);
						});
						that.favoriteList = [...that.favoriteList, ...list];
						that.isEmpty = !that.favoriteList.length;
						that.lastPage = res.data.last_page;
						that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
					}
				});
			},*/
			getMyArticleList() {
				let that = this;
				let list = [];
				that.loadStatus = 'loading';
				that.$http('news.mypushList', {
					pre_page: 10,
					page: that.currentPage
				}).then(res => {
					if (res.code === 1) {
						that.total = res.data.total;
						list = res.data.data;
						list.map(item => {
							that.$set(item, 'checked', false);
						});
						that.myarticleList = [...that.myarticleList, ...list];
						that.isEmpty = !that.myarticleList.length;
						that.lastPage = res.data.last_page;
						that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.head_box {
		height: 70rpx;
		padding: 0 30rpx;

		.count-box {
			font-size: 26rpx;
			color: #999;

			.all-num {
				color: #a8700d;
			}
		}

		.set-btn {
			background: none;
			font-size: 26rpx;
			color: #a8700d;
			padding: 20rpx;
		}
	}

	.collect-list {
		padding: 30rpx 20rpx;
		background: #fff;
		width: 750rpx;
		margin-bottom: 20rpx;
	}

	.tools-box {
		height: 100rpx;
		width: 750rpx;
		padding: 0 20rpx;
		background: #fff;

		.close-btn {
			width: 200rpx;
			line-height: 70rpx;
			background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
			box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
			border-radius: 35rpx;
			padding: 0;
			color: rgba(#fff, 0.9);
		}
	}
</style>
